﻿using System.Net;
using WWB.DisqusSharp.Model.DisqusService;
using Hammock;

namespace WWB.DisqusSharp.Infrastructure.HammockWrappers
{
    public abstract class HammockServiceBase
    {
        protected abstract RestClient GetRestClient();
       

        protected IDisqusServiceResult<T> ExecuteRequest<T>(RestRequest request) where T : class
        {
            var restClient = GetRestClient();
            var restResp = restClient.Request(request);
            if (restResp.StatusCode == HttpStatusCode.OK)
            {
                var swrap = new DisqusServiceResultWrapper<T>(restResp.Content);
                return swrap;
            }
            var errwrap = new DisqusServiceErrorWrapper<T>(restResp.Content);
            return errwrap;
        }
    }
}